<!--无限极左侧菜单-->
<div class="left-menu-panel">
    <div class="layui-nav layui-nav-tree">
        <div class="layui-nav-item layui-nav-itemed" id="searcherMenuPanel">
            <a href="javascript:;">候选人搜索器</a>
            <searcher-menu-modular :data="menuList" ref="searcherMenuModular" @menu-change="handleMenuChange" @menu-delete="handleDeleteMenu"></searcher-menu-modular>
        </div>
        <div class="layui-nav-item layui-nav-itemed" id="folderMenuPanel">
            <a href="javascript:;">候选人收藏夹 <span class="fav-edit" @click="handleFolderEdit">编辑</span></a>
            <folder-menu-modular :data="menuList" ref="folderMenuModular" :current-id="currentId" @menu-change="handleMenuChange"></folder-menu-modular>
        </div>
        <div class="layui-nav-item layui-nav-itemed" id="smartMenuPanel">
            <a href="javascript:;">智能分类 <span class="fav-edit" @click="handleSmartEdit">编辑</span></a>
            <smart-menu-modular :data="menuList" ref="smartMenuModular" :current-id="currentId" @menu-change="handleMenuChange"></smart-menu-modular>
        </div>
    </div>
</div>
<div class="right-panel layuimini-page-anim">
    <form class="layui-form layui-user-from" action="">
        <div class="layui-row">
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label label-required">行业</label>
                    <div class="layui-input-block">
                        <div lay-event="xm-select-industry"></div>
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">职能</label>
                    <div class="layui-input-block">
                        <select name="status">
                            <option value=""></option>
                            <option value="0">下拉框</option>
                            <option value="1">下拉框</option>
                            <option value="2">下拉框</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">收藏夹</label>
                    <div class="layui-input-block">
                        <input type="text" name="folder_id" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">城市</label>
                    <div class="layui-input-block">
                        <div lay-event="xm-select-city"></div>
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">职位</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">标签</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">手机</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">排除</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">加过订单</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">语言</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">意向城市</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">其他</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">备注相关</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">ID</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">学历</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">分类</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">年薪</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">年龄/年限</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">生日</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">优质</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">国籍</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">来源</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">婚育情况</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">附件相关</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">时间查询</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">最近联系</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">全文检索</label>
                    <div class="layui-input-block">
                        <input type="text" name="company_name" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md12">
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-xs layui-bg-lightblue" lay-submit lay-filter="candidateSearch">搜索</button>
                        <button type="reset" class="layui-btn layui-btn-xs layui-btn-primary">清空</button>
                        <a href="javascript:;" class="color-blue ml-10 js-btn-more">更多 <i class="fa fa-angle-double-left"></i></a>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <div class="layui-table-modular" style="min-height: 700px">
        <table class="layui-hide" id="candidateTable" lay-filter="candidateTable" lay-skin="line"></table>
    </div>
</div>

<!-- 工具栏 -->
<script type="text/html" id="toolbarTemp">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-xs layui-btn-primary" lay-event="add">新增候选人</button>
        <a layuimini-href="page/welcome.html" class="layui-btn layui-btn-xs layui-btn-primary" >链接</a>
        <button class="layui-btn layui-btn-xs layui-btn-primary needCheck layui-btn-disabled">短信</button>
        <button class="layui-btn layui-btn-xs layui-btn-primary needCheck layui-btn-disabled">邮件</button>
        <button class="layui-btn layui-btn-xs layui-btn-primary needCheck layui-btn-disabled">加入订单</button>
        <button class="layui-btn layui-btn-xs layui-btn-primary needCheck layui-btn-disabled">加入收藏</button>
        <div class="layui-dropdown" lay-filter='moreFunction'>
            <button class="layui-btn layui-btn-xs layui-btn-primary layui-dropdown-toggle needCheck layui-btn-disabled">更多功能</button>
            <div class="layui-dropdown-content">
                <div class="layui-dropdown-menu">
                    <li><a href="javascript:;" lay-event="deleteTableData">删除</a></li>
                    <li><a href="javascript:;" lay-event="mergeTableData">合并</a></li>
                </div>
            </div>
        </div>
    </div>
</script>
<!-- 表格自定义下拉temp -->
<script type="text/html" id="enclosureDropdownTemp">
    <div class="layui-dropdown" lay-filter='enclosure' data-id="{{d.id}}">
        <a href="javascript:;" class="layui-dropdown-toggle"><i class="fa fa-paperclip"></i> 0</a>
        <div class="layui-dropdown-content">
            <div class="enclosure-dialog">
                <div class="hd">
                    <select name="tag" class="ed-tag" lay-ignore>
                        <option value="0">简历原件</option>
                        <option value="1">照片</option>
                    </select>
                    <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary handleUploadFile" data-type="candidate">选择文件</a>
                </div>
                <ul class="list"></ul>
            </div>
        </div>
    </div>
</script>
<script type="text/html" id="enclosureTemp">
    {{#  layui.each(d, function(index, item){ }}
    <li class="layui-row">
        <div class="layui-col-md12">
            <div class="pull-left">
                <i class="fa fa-paperclip mr-5"></i>
                <a href="javascript:;" class="color-blue mr-5 ellipsis-l1" style="max-width: 300px">{{ item.originname }}</a>
                {{#  if(item.type_value == 0){ }}
                <span class="layui-badge layui-bg-orange">原始简历</span>
                {{#  } else if (item.type_value == 1) { }}
                <span class="layui-badge layui-bg-lightblue">照片</span>
                {{#  } }}
            </div>
            <div class="pull-right">
                <span class="color-gray">{{ (item.filesize/1024).toFixed(1) }} KB</span>
            </div>
        </div>
        <div class="layui-col-md12">
            <div class="pull-left">上传者:{{ item.addedBy.name }}  {{item.dateAdded}}</div>
            <div class="pull-right">
                <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary" data-id="{{item.id}}">预览</a>
                <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary deleteFile" data-id="{{item.id}}">删除</a>
                <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary replaceFile" data-id="{{item.id}}">替换</a>
                <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary">下载</a>
            </div>
        </div>
    </li>
    {{#  }); }}
</script>
<!-- 操作 -->
<script type="text/html" id="operationTemp">
    <div class="layui-dropdown dropdown-right" lay-filter='operation'>
        <button class="layui-btn layui-btn-xs layui-btn-primary layui-dropdown-toggle"><i class="fa fa-align-justify"></i></button>
        <div class="layui-dropdown-content">
            <div class="layui-dropdown-menu">
                <li><a href="javascript:;">关注</a></li>
                <li><a href="javascript:;" lay-event="edit">编辑简历</a></li>
                <li><a href="javascript:;" layuimini-href="page/welcome.html">编辑简历2</a></li>
                <li><a href="javascript:;">修改简历正文</a></li>
                <li><a href="javascript:;">提醒</a></li>
                <li><a href="javascript:;">Floating CV</a></li>
                <hr>
                <li><a href="javascript:;">加入订单</a></li>
                <li><a href="javascript:;">加入收藏</a></li>
            </div>
        </div>
    </div>
</script>
<!--状态-->
<script type="text/html" id="tableBarTemp">
    {{#  if(d.status == 0){ }}
    <button class="layui-btn layui-btn-xs layui-bg-orange">空缺Vacant</button>
    {{#  } }}
    {{#  if(d.status == 1){ }}
    <button class="layui-btn layui-btn-xs">取消Cancelled</button>
    {{#  } }}
    {{#  if(d.status == 2){ }}
    <button class="layui-btn layui-btn-xs layui-bg-red">完成Filled</button>
    {{#  } }}
    {{#  if(d.status == 3){ }}
    <button class="layui-btn layui-btn-xs layui-bg-black">Unfilled</button>
    {{#  } }}
</script>
<script>
    layui.use(['form', 'table', 'miniPage', 'element', 'laydate', 'laytpl', 'xmSelect', 'utils', 'upload', 'searcherMenu', 'folderMenu', 'smartMenu', 'cookie'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            xmSelect = layui.xmSelect,
            utils = layui.utils,
            element = layui.element,
            upload = layui.upload,
            searcherMenu = layui.searcherMenu,
            folderMenu = layui.folderMenu,
            smartMenu = layui.smartMenu,
            cookie = layui.cookie;


        form.render(); // 初始化表单


        // 需要xmSelect初始化表单
        var xmSelectUnit = function () {
            this.getCityData(); // 城市
            this.getIndustryData(); // 行业
        };
        xmSelectUnit.prototype = {
            initCity: function () {
                var xmSelectCity = xmSelect.render({
                    el: '[lay-event="xm-select-city"]',
                    prop: {
                        name: 'label',
                        value: 'id',
                    },
                    name: 'citys',
                    theme: {
                        color: '#84d0e8',
                    },
                    filterable: true,
                    tree: {
                        show: true,
                        showFolderIcon: true,
                        showLine: true,
                        indent: 20,
                        expandedKeys: [ -3 ],
                        lazy: true
                    },
                    on: function(data){
                        if(data.isAdd){
                            return data.change.slice(0, 1)
                        }
                    },
                    toolbar: {
                        show: true,
                        list: ['ALL', 'REVERSE', 'CLEAR']
                    },
                    data: []
                });
                return xmSelectCity;
            },
            getCityData: function () {
                var that = this;
                utils.Ajax({
                    url: 'api/city.json',
                    dataType: 'json',
                    type: 'post',
                    data: {},
                    success: function (response) {
                        var citylist = response.data.city;
                        if (Array.isArray(citylist)) {
                            that.initCity().update({
                                data: citylist
                            })
                        }
                    }
                });
            },
            initIndustry: function () {
                var xmSelectIndustry = xmSelect.render({
                    el: '[lay-event="xm-select-industry"]',
                    prop: {
                        name: 'label',
                        value: 'id',
                    },
                    name: 'industry',
                    theme: {
                        color: '#84d0e8',
                    },
                    filterable: true,
                    tree: {
                        show: true,
                        showFolderIcon: true,
                        showLine: true,
                        indent: 20,
                        expandedKeys: [ -3 ],
                        lazy: true
                    },
                    toolbar: {
                        show: true,
                        list: ['ALL', 'REVERSE', 'CLEAR']
                    },
                    data: []
                });
                return xmSelectIndustry;
            },
            getIndustryData: function () {
                var that = this;
                utils.Ajax({
                    url: 'api/city.json',
                    dataType: 'json',
                    type: 'post',
                    data: {},
                    success: function (response) {
                        var citylist = response.data.city;
                        if (Array.isArray(citylist)) {
                            that.initIndustry().update({
                                data: citylist
                            })
                        }
                    }
                });
            }
        };

        new xmSelectUnit();

        /**
         * 搜索器+table渲染
         */
        var searcherMenuConfig = {
            el: '#searcherMenuPanel',
            menuInfoUrl: 'api/common/nav.json',
            queryKey: 'baseSearchId',
            menuChangeCallback: function(id) {
               if (id) {
                   // 重载表格
                   candidateTableIns.reload({
                       url: 'api/candidateTable.json?baseSearchId=' + id,
                       where: false,
                       page: {
                           curr: 1
                       }
                   });
                   // 生成智能分类导航
                   thatSmartMenu.getMenuInfo(id)
               }
            }
        };
        var thatSearchMenu = searcherMenu.initSearcherMenu(searcherMenuConfig);
        // 更新搜索器 thatSearchMenu.getMenuInfo();


        /**
         * 收藏夹+table渲染
         */
        var foldMenuConfig = {
            el: '#folderMenuPanel',
            menuInfoUrl: 'api/common/nav2.json',
            queryKey: 'folderId',
            menuChangeCallback: function(config) {
                if (config) {
                    var params = $.param(config);
                    // 重载表格
                    candidateTableIns.reload({
                        url: 'api/candidateTable.json?' + params,
                        where: false,
                        page: {
                            curr: 1
                        }
                    });
                }
            }
        };
        window.thatFolderMenu = folderMenu.initFolderMenu(foldMenuConfig);
        // 更新收藏夹 thatFolderMenu.getMenuInfo();


        /**
         * 智能分类+table渲染
         */
        var smartMenuConfig = {
            el: '#smartMenuPanel',
            menuInfoUrl: 'api/common/smartNav.json',
            queryKey: 'smartId',
            menuChangeCallback: function(config) {
                if (config) {
                    var params = $.param(config);
                    // 重载表格
                    candidateTableIns.reload({
                        url: 'api/candidateTable.json?' + params,
                        where: false,
                        page: {
                            curr: 1
                        }
                    });
                }
            }
        };
        window.thatSmartMenu = smartMenu.initSmartMenu(smartMenuConfig);
        // 更新智能分类 thatSmartMenu.getMenuInfo();




        // 数据快速查看
        var candidateTableIns = table.render({
            elem: '#candidateTable',
            url: 'api/candidateTable.json',
            method: 'get',
            page: true,
            xiaohui: {
                sex: 0
            },
            contentType: 'application/json',
            headers: {"token": sessionStorage.getItem("token")},
            request: {
                pageName: 'pageIndex',
                limitName: 'pageSize'
            },
            response: {
                statusCode: 200
            },
            parseData: function(res){
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.total,
                    "data": res.data.records
                };
            },
            toolbar: '#toolbarTemp',
            defaultToolbar: ['filter'],
            skin: 'line',
            cols: [
                [
                    {type: 'checkbox'},
                    {type: 'enclosure', align: 'center', title: '', width: 50, templet: '#enclosureDropdownTemp'},
                    {type: 'remarks', align: 'center', title: '', width: 50, templet: function(d){
                            return '<a href="javascript:;" lay-event="remarks"><i class="fa fa-comment-o"></i> 0</a>'
                        }},
                    {field: 'name', align: 'center', title: '姓名'},
                    {field: 'company', align: 'center', title: '公司', templet: function(d){
                            return '<a href="javascrpt:;" class="color-blue">'+ d.companyname +'</a>'
                        }},
                    {field: 'position', align: 'center', title: '职位'},
                    {field: 'location', align:'center', title: '城市', width: 120},
                    {field: 'annualSalary', align:'center', title: '年薪', width: 60},
                    {field: 'dateOfBirth', align:'center', title: '年龄', width: 60},
                    {field: 'mobile', align:'center', title: '手机', width: 60},
                    {field: 'tags', align:'center', title: '标签', width: 60},
                    {field: 'status', title: '状态', templet: '#tableBarTemp'},
                    {field: 'lastUpdateDate', align:'center', title: '最近联系', width: 100},
                    {title: '操作', align: "center", fixed: "right", width: 60, templet: '#operationTemp'}
                ]
            ],
            done: function(res, curr, count){
                // 更多功能
                utils.dropdown({
                    el: '[lay-filter="moreFunction"]',
                    zIndex: 10000,
                    trigger: 'click'
                });
                // 附件
                $('[lay-filter="enclosure"]').each(function () {
                    var $this = $(this);
                    var id = $this.data('id');
                    utils.dropdown({
                        el: $this,
                        zIndex: 10000,
                        trigger: 'click',
                        onShow: function ($dom) {
                            utils.Ajax({
                                url: 'api/talent_file_list.json', // 附件列表
                                dataType: 'json',
                                type: 'post',
                                data: {id: id},
                                success: function (response) {
                                    var fileList = response.data.fileList;
                                    createEnclosureDom(id, fileList, $dom);
                                }
                            })
                        }
                    });
                });
                // 操作
                $('[lay-filter="operation"]').each(function () {
                    var $this = $(this);
                    utils.dropdown({
                        el: $this,
                        zIndex: 10000,
                        trigger: 'click'
                    });
                });
            }
        });

        // 编辑收藏夹

        /**
         *  附件
         */
        function uploadEnclosure(resumeId, fileList, $dom) {
            var $upload = $dom.find('.handleUploadFile');
            var _type = $upload.data('type');
            if ($upload.data('init')) return;
            var uploadInst = upload.render({
                elem: $upload,
                url: 'api/talent/upload_file.json', //上传接口
                headers: {"token": sessionStorage.getItem("token")},
                data: {
                    id: resumeId,
                    tag: function () {
                        return $dom.find('.ed-tag').val()
                    },
                    type: _type
                },
                accept: 'file',
                before: function(obj){
                    var _temp = '<div class="layui-progress mt-5" lay-filter="progress">' +
                        '<div class="layui-progress-bar layui-bg-lightblue"></div>' +
                        '</div>';
                    $upload.after(_temp);
                },
                progress: function(n, elem){
                    var percent = n + '%';
                    element.progress('progress', percent);
                },
                done: function(res){
                    if (res.code === 200) {
                        layer.msg(res.message);
                        fileList.unshift(res.data.file);
                        // 移除进度条
                        $upload.next('.layui-progress').remove();
                        // 填充数据
                        createEnclosureDom(resumeId, fileList, $dom);
                    }
                },
                error: function(){
                    layer.msg('请求错误！');
                }
            });
            $upload.data('init', true);
        }
        function createEnclosureDom(resumeId, fileList, $dom) {
            laytpl($('#enclosureTemp').html()).render(fileList, function(html){
                $dom.find('.enclosure-dialog > .list').html(html);
            });
            // 删除
            $dom.find('.deleteFile').on('click', function () {
                var _id = $(this).data('id');
                utils.Ajax({
                    url: 'api/talent/enc_del.json',
                    dataType: 'json',
                    type: 'post',
                    data: {id: _id},
                    success: function (response) {
                        layer.msg(response.message);
                        utils.dataDelete(_id, fileList);
                        createEnclosureDom(resumeId, fileList, $dom)
                    }
                })
            });
            // 替换
            $dom.find('.replaceFile').on('click', function () {
                var _id = $(this).data('id');
                utils.Ajax({
                    url: '',
                    dataType: 'json',
                    type: 'post',
                    data: {id: _id},
                    success: function (response) {
                        layer.msg(response.message);
                    }
                })
            });
            // 初始化上传
            uploadEnclosure(resumeId, fileList, $dom);
        }

        /**
         *  表单事件
         */

        //搜索
        form.on('submit(candidateSearch)', function(data){
            candidateTableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });

        //监听头部工具栏
        table.on('toolbar(candidateTable)', function(obj){
            switch(obj.event){
                // 新增候选人
                case 'add':
                    var content = miniPage.getHrefContent('page/talent/add.html');
                    if (content) {
                        var index = layer.open({
                            title: '编辑候选人',
                            type: 1,
                            shade: 0.2,
                            maxmin:true,
                            area: ['98%', '90%'],
                            content: content,
                            btn: ['确认', '取消'],
                            btnAlign: 'c',
                            success: function (layero, index) {
                                $(window).on("resize", resizeLayer = function () {
                                    layer.full(index);
                                });
                            },
                            yes: function(index, layero){
                                window.talentDialogContent.handleSubmitBtnClick();
                            },
                            end: function(){
                                $(window).off("resize", resizeLayer);
                                delete window.resizeLayer;
                                delete window.talentDialogContent;
                            }
                        });
                    }
                    break;
                // 删除选中数据
                case 'deleteTableData':
                    var checkStatus = table.checkStatus('candidateTable');
                    var arr = [];
                    checkStatus.data.forEach(function(item) {
                        arr.push(item.id)
                    });
                    layer.confirm('确定要删除吗？', {title: '信息', btn: ['确定', '删除']}, function(index){
                        utils.Ajax({
                            url: '',
                            dataType: 'json',
                            type: 'post',
                            data: {data: JSON.stringify(arr)},
                            success: function (response) {
                                candidateTableInsObj.reloadTable();
                                layer.close(index);
                            }
                        });
                    });
                    break;
            }
        });

        //监听工具条
        table.on('tool(candidateTable)', function (obj) {
            var data = obj.data;
            window.userId = data.id;
            switch(obj.event){
                case 'edit':
                    var content = miniPage.getHrefContent('page/talent/add.html');
                    if (content) {
                        var index = layer.open({
                            title: '编辑候选人',
                            type: 1,
                            shade: 0.2,
                            maxmin:true,
                            area: ['98%', '90%'],
                            content: content,
                            btn: ['确认', '取消'],
                            btnAlign: 'c',
                            success: function (layero, index) {
                                $(window).on("resize", resizeLayer = function () {
                                    layer.full(index);
                                });
                            },
                            yes: function(index, layero){
                                window.talentDialogContent.handleSubmitBtnClick();
                            },
                            end: function(){
                                $(window).off("resize", resizeLayer);
                                delete window.resizeLayer;
                                delete window.talentDialogContent;
                                delete window.userId;
                            }
                        });
                    }
                    break;
                case 'remarks':
                    var content = miniPage.getHrefContent('page/talent/remarkTalent.html');
                    layer.open({
                        title: '备注',
                        area:['1000px','90%'],
                        type: 1,
                        shade: 0.2,
                        maxmin:true,
                        content: content,
                        btn: ['确认', '取消'],
                        btnAlign: 'c',
                        yes: function(index, layero){
                            var $remarkForm = layero.find('.remark-form').not('.layui-hide');
                            $remarkForm.find('[lay-filter="saveBtn"]').click();
                        },
                    });
            }
        });

        //监听复选框
        table.on('checkbox(candidateTable)', function(obj){
            var $needCheck = $('.layui-table-tool-temp').find('.needCheck');
            obj.checked ? $needCheck.removeClass('layui-btn-disabled') : $needCheck.addClass('layui-btn-disabled');
        });
    });
</script>
